package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.AgentTypeVo;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.detailagentTypeBean;
import com.ymatou.iapi.godmch.parameter.listagentTypeBean;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.detailagentTypeCall;
import com.ymatou.iapi.godmch.service.listagentTypeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
/**
*代理类型列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_listgentType{
	private static listagentTypeBean bean;
	private static listagentTypeCall listgenttypecall;
	private static agent_typeWapper agenttypeWapper=new agent_typeWapper();
	private static mch_relationWapper mchrelationWapper=new mch_relationWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("代理类型列表");
	}

	@Before
	public void caseUp() {
		bean=new listagentTypeBean();
		listgenttypecall=new listagentTypeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(listgenttypecall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_listgentType__001() {
		Logger.start(true,"代理类型列表,验证商户id-返回正常");
		try {
			//新增商户
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int mchId=createmchbean.getMchId();
	        //新增代理
            createagentBean createagentbean=GodmchManageCallService.InitCreateAgentTypeBean(mchId);
            createagentCall createagentcall=GodmchManageCallService.CreateAgentTypeCall(createagentbean);
            
			bean.setMchId(mchId);
			listgenttypecall.setData(bean);
			listgenttypecall.callService();		
			Logger.verifyEquals("200", listgenttypecall.getString("status"), "验证status");
			List<AgentTypeVo> returnList=listgenttypecall.getAgentTypes();
			//agent_type
	        Map<String,Object> map2=new HashMap();
	        map2.put("mchId", mchId);
	        List<agent_type>  agenttypeList =agenttypeWapper.selectby(map2);
	        Logger.verifyEquals(agenttypeList.size(),returnList.size(), "验证数据库agent_type数据与返回数据一致");
	        for(int i=0;i<returnList.size();i++)
	        {
	        	Logger.verifyEquals(returnList.get(i).getTitle(),agenttypeList.get(i).getTypeTitle(),"验证第"+(i+1)+"个代理类型,数据库agent_type表typeTitle与返回Title数据一致");
	        	Logger.verifyEquals(returnList.get(i).getRemark(),agenttypeList.get(i).getRemark(),"验证第"+(i+1)+"个代理类型,数据库agent_type表Remark与返回Remark数据一致");
	        	Logger.verifyEquals(returnList.get(i).getSeqNo(),agenttypeList.get(i).getSeqNo(),"验证第"+(i+1)+"个代理类型,数据库agent_type表SeqNo与返回SeqNo数据一致");
	        	
	        	Map<String,Object> map=new HashMap();
	 	        map.put("agentType", agenttypeList.get(i).getAgentType());
	 	        int count=mchrelationWapper.selectby(map).size();
	        	Logger.verifyEquals(count,returnList.get(i).getUsedAgent(),"验证第"+(i+1)+"个代理类型,使用人数与返回usedAgent数据一致");
	        }
	        
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_listgentType__002() {
		Logger.start(true,"代理类型列表,验证商户id不存在,返回错误");
		try {
            
			bean.setMchId(9999);
			listgenttypecall.setData(bean);
			listgenttypecall.callService();			
			List<AgentTypeVo> returnList=listgenttypecall.getAgentTypes();
			Logger.verifyEquals("200", listgenttypecall.getString("status"), "验证status");
			Logger.verifyIsNull(returnList, "验证无数据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_listgentType__003() {
		Logger.start(true,"代理类型列表,验证商户id为空,返回错误");
		try {
			listgenttypecall.setData(bean);
			listgenttypecall.callService();			
			Logger.verifyEquals("4001", listgenttypecall.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}